import request from '@/utils/request/request';
import {
  APIAddParams,
  APIDetailInfo,
  APIListRes,
  ExecuteAPI,
  APIBascCressForm,
} from '@/api/infrastructure/model/apiModal';
//   APIParams,

// 品类管理列表查询
export function queryAPIRecordListByPage(params: APIBascCressForm) {
  return request.get<APIBascCressForm>('/api/procurement/infra/category/list', {
    params,
  });
}

// 新增品类API
export function categoryAddlist(data: APIAddParams) {
  return request.post('/api/procurement/infra/category', data);
}

// 修改API
export function updateAPIRecord(data: APIAddParams) {
  return request.put('/api/procurement/infra/category', data);
}
// 删除API
export function deleteAPIRecord(id: string) {
  return request.delete(`/api/procurement/infra/category/${id}`);
}
// 批量删除删除API
export function checkdeleteAPIRecord(params: any) {
  return request.delete(`/api/procurement/infra/category/`, {
    data: params,
  });
}

// 属性采购维护
export function queryAPICglist(params: any) {
  console.log(params);
  return request.get<APIListRes>(
    '/api/procurement/infra/procurement-attribute/page',
    {
      params,
    }
  );
}

// 人员物料维护
export function queryrywlAPICglist(params: any) {
  return request.get<APIListRes>(
    '/api/procurement/infra/user-material-config/pageRelationship',
    {
      params,
    }
  );
}

// 采购属性维护删除API
export function proUrementdeleteAPI(id: string) {
  return request.delete(`/api/procurement/infra/category/${id}`);
}
// 采购属性批量删除删除API
export function procurementAPIRecord(params: any) {
  return request.delete(`/api/procurement/infra/procurement-attribute/`, {
    data: params,
  });
}
// 采购属性维护下载模版
export function downloadFile() {
  return request.get(
    '/api/procurement/infra/procurement-attribute/download/template'
  );
}
// 采购属性维护数据导入
export function purchaseImportExcelToData(data: FormData) {
  return request.post(
    '/api/procurement/infra/procurement-attribute/import',
    data,
    {
      headers: {
        'Content-Type': 'application/form-data',
      },
    }
  );
  // return request.post(
  //   '/api/procurement/infra/procurement-attribute/download/template',
  //   data,
  //   {
  //     headers: {
  //       'Content-Type': 'application/form-data',
  //     },
  //   }
  // );
}
// 人员物料维护
export function querymaterialAPICglist(params: any) {
  return request.get<APIListRes>(
    '/api/procurement/infra/user-material-config/page',
    {
      params,
    }
  );
}

// 单一来源控制清单列表查询
export function getSingleSourceList(params: APIBascCressForm) {
  return request.get<APIBascCressForm>(
    '/api/procurement/infra/unique-control/page',
    {
      params,
    }
  );
}
// 单一来源控制清单添加
export function addMainTable(params: APIBascCressForm) {
  console.log(params, 'params');
  return request.post<APIBascCressForm>(
    '/api/procurement/infra/unique-control',
    params
  );
}
// 单一来源控制清单详情
export function detailsData(id: string) {
  return request.get(`/api/procurement/infra/unique-control?id=${id}`);
}
// 单一来源控制清单明细编辑
export function editMainTable(params: APIBascCressForm) {
  console.log(params);
  return request.put<APIBascCressForm>(
    '/api/procurement/infra/unique-control',
    params
  );
}
// 单一来源控制清单列表删除
export function delSingleList(params: any) {
  return request.delete('/api/procurement/infra/unique-control', {
    data: params,
  });
}
// 单一来源控制清单明细列表查询
export function getOrderDetailsList(params: APIBascCressForm) {
  return request.get<APIBascCressForm>(
    '/api/procurement/infra/unique-control-detail/unique/page',
    {
      params,
    }
  );
}
// 单一来源控制清单明细列表删除
export function delDetailsLeList(id: string) {
  return request.delete(`/api/procurement/infra/unique-control/${id}`);
}

// 单一来源控制清单明细表添加
export function addMSubTable(params: APIBascCressForm) {
  console.log(params, 'params');
  return request.post<APIBascCressForm>(
    '/api/procurement/infra/unique-control-detail',
    params
  );
}
// 单一来源控制清单明细编辑
export function editSubTable(params: APIBascCressForm) {
  console.log(params);
  return request.put<APIBascCressForm>(
    '/api/procurement/infra/unique-control-detail',
    params
  );
}
// 单一来源控制清单详情
export function detailsSubTable(id: string) {
  return request.get(`/api/procurement/infra/unique-control-detail/${id}`);
}
// 单一来源控制清单列表删除
export function delSubTable(params: any) {
  return request.delete('/api/procurement/infra/unique-control-detail', {
    data: params,
  });
}

// 根据APIid查API详细信息
export function getAPIDetailInfoById(id: string) {
  return request.get<APIDetailInfo>(`/api/infra/form-api/${id}`);
}

// 通过子级id获得父级品类详情
export function getParentById(params: object) {
  return request.get<APIDetailInfo>(`/api/procurement/infra/category/parent`, {
    params,
  });
}

// 执行API
export function executeAPI(path: string, data: ExecuteAPI) {
  return request.post(`/api/infra/form-api/custom/${path}`, data);
}

// 采购属性维护
export function procurementAttributeByPage(params: any) {
  console.log(params);
  return request.get<APIBascCressForm>(
    '/api/procurement/infra/procurement-attribute/page',
    {
      params,
    }
  );
}

// 采购属性批量修改API
export function editProcurement(params: any) {
  return request.put(`/api/procurement/infra/procurement-attribute`, params);
}

// 导入Excel
export function importExcelToData(data: FormData) {
  return request.post(
    '/api/procurement/infra/procurement-attribute/import',
    data,
    {
      headers: {
        'Content-Type': 'application/form-data',
      },
    }
  );
}
